<template>
	<view style="height: 60rpx; width: 100%;"></view>
	<view class="container" @click="navigateToIndex" :style="{ backgroundImage: `url(${picUrl})` }">
	</view>
</template>

<script>
import {
	getPic
} from '@/api/points'
export default {
	data() {
		return {
			// picUrl: uni.getStorageSync('picUrl'),
			picUrl: 'https://mhkj001.oss-rg-china-mainland.aliyuncs.com/index_image/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20250508215419.png',
			toUrl: uni.getStorageSync('toUrl'),
		}
	},
	methods: {
		getPic(params) {
				if (params) {
					getPic({
						bs: params
					}).then(res => {
						// this.picUrl = res.data[0].pic
						this.sourceUrl = res.data[0].url
						// this.toUrl = res.data[0].tourl
						uni.setStorageSync('route', this.sourceUrl)
						uni.setStorageSync('mt', res.data[0].mt)
						// uni.setStorageSync('picUrl', this.picUrl)
						// uni.setStorageSync('toUrl',this.toUrl)
						/* if (!this.picUrl) {
							this.navigateToIndex()
						}else{
							uni.navigateTo({
								url:"/pages/advertisement/advertisement"
							})
						} */
					})
				} 
				/* else {
					uni.navigateTo({
						url:"/pages/index/index"
					})
				} */
			},
		navigateToIndex() {
			// if (uni.getStorageSync('toUrl')) {
			// 	window.location.href = uni.getStorageSync('toUrl')
			// } else {
				uni.navigateTo({
					url: '/pages/index/index'
				})
			// }

		},
		getUrlParam(name) {
			// 获取完整的URL的查询参数部分
			const searchParams = new URLSearchParams(window.location.search)
			const hashParams = new URLSearchParams(window.location.hash.split('?')[1] || '')

			// 优先从 search 中获取，没有则从 hash 中获取
			return searchParams.get(name) || hashParams.get(name) || null
		},
	},
	onLoad() {
		console.log('advertisement onLoad')
		// this.getPic(window.location.hash.split('=')[1])
		let bs = this.getUrlParam('bs')
		this.getPic(bs)
	},
	onShow() {
		console.log('advertisement onShow')
		/* setTimeout(() => {
			if (!this.picUrl) {
				this.navigateToIndex()
			}
		}, 300); */
		/* let bs = this.getUrlParam('bs')
		this.getPic(bs) */

	}
}
</script>

<style>
.container {
	width: 100vw;
	height:calc(100vh - 60rpx);
	position: relative;
	background-repeat: no-repeat;
	background-size: 100%;
	background-position: top;
}
</style>